package com.example.online.music.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.online.music.mapper.PlayRecordMapper;
import com.example.online.music.mapper.RecommendMapper;
import com.example.online.music.model.domain.PlayRecord;
import com.example.online.music.model.domain.Recommend;
import com.example.online.music.service.PlayRecordService;
import com.example.online.music.service.RecommendService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Map;
import java.util.function.BiConsumer;

/**
 * @Description: 播放记录业务处理类
 * @Author: yang_yong
 */
@Service
public class RecommendServiceImpl extends ServiceImpl<RecommendMapper, Recommend> implements RecommendService {

    @Autowired
    private RecommendMapper recommendMapper;

    /**
     * @Description: 向推荐表中写入推荐数据
     * @param: user2songRecMatrix
     */
    @Transactional
    @Override
    public void updatePersonalRecInfo(Map<Integer, Integer[]> user2songRecMatrix) {
        user2songRecMatrix.forEach((userId, songIds) -> {
            recommendMapper.deleteByUserId(userId);
            recommendMapper.batchInsert(userId, songIds);
        });
    }
}
